home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1996 May / Software of the Month Club 1996 May.iso / mac / ISO9660 / OS2 / MESA / EXAMPLES / SRC / PAGE / PAGE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-11  |  2.2 KB  |  149 lines  |  [TEXT/hscd]

  1. #include "os2h.h"
  2.  
  3. extern "C"
  4. {
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include <string.h>
  8. }
  9.  
  10. #define LWD
  11.  
  12.  
  13. HAB myHab;
  14. HMQ myHmq;
  15.  
  16. HWND myFrame,myText;
  17.  
  18.  
  19. int forkThread(void *func,void *data)
  20. {
  21.     ULONG tmp;
  22.  
  23. #ifdef BORLAND
  24.     DosCreateThread(&tmp,(PFNTHREAD) func,(ULONG) data,0,32 * 1024);
  25. #else
  26.     tmp = _beginthread(( void ( * _Optlink  )( void * ))func,(int) NULL,32 * 1024,data);
  27. #endif
  28.  
  29.     return tmp;
  30. }
  31.  
  32. static int dialing = 0;
  33.  
  34. void dial(void *)
  35. {
  36.     if (!dialing) {
  37.         FILE *num,*ser;
  38.         char tmp[1000];
  39.  
  40.         dialing = 1;
  41.  
  42.         num = fopen("c:/Mesa/phone.num","r");
  43.         if (num) {
  44.             fscanf(num,"%s\n",tmp);
  45.             fclose(num);
  46.  
  47.             ser = fopen("com1","w");
  48.             if (ser) {
  49.                 fprintf(ser,"%s\n",tmp);
  50.                 DosSleep(45000);
  51.                 fclose(ser);
  52.             }
  53.         }
  54.  
  55.  
  56.         dialing = 0;
  57.     }
  58. }
  59.  
  60. MRESULT EXPENTRY myPageWindowProc(HWND hw,ULONG msg,MPARAM mp1,MPARAM mp2)
  61. {
  62.     int handled = 1;
  63.     MRESULT ret = 0;
  64.  
  65.     switch (msg) {
  66.         case WM_INITDLG:
  67.             myFrame = hw;
  68.             myText = WinWindowFromID(hw,101);
  69.             handled = 0;
  70.             break;
  71.  
  72.         case WM_USER:
  73.             WinSetWindowText(myText,(PSZ)mp1);
  74.             if (strlen((char *) mp1) > 2) {
  75.                 forkThread(dial,NULL);
  76.             }
  77.  
  78.             free((void *)mp1);
  79.             break;
  80.  
  81.         default:
  82.             handled = 0;
  83.     }
  84.  
  85.     if (!handled) ret = WinDefDlgProc(hw,msg,mp1,mp2);
  86.  
  87.     return ret;
  88.  
  89. }
  90.  
  91.  
  92. void listenToPort(void *)
  93. {
  94.     HFILE phil;
  95.     char *t;
  96.  
  97.     DosCreateNPipe((PSZ) "\\pipe\\Pager",&phil,
  98.         NP_ACCESS_INBOUND | NP_NOINHERIT | NP_WRITEBEHIND,
  99.         NP_WAIT | NP_TYPE_MESSAGE | NP_READMODE_MESSAGE | 1,
  100.         4096,4096,0);
  101.  
  102.     for (;;) {
  103.         char n1[256];
  104.         ULONG len;
  105.  
  106.         DosConnectNPipe(phil);
  107.         DosRead(phil,&n1,sizeof(n1),&len);
  108.         if (len == sizeof(n1)) {
  109.             t = (char *) malloc(sizeof(n1));
  110.             strcpy(t,n1);
  111.             WinPostMsg(myFrame,WM_USER,(MPARAM) t,0);
  112.         }
  113.         DosDisConnectNPipe(phil);
  114.     }
  115. }
  116.  
  117. void clearDisplay(void *)
  118. {
  119.     for (;;) {
  120.         char *t;
  121.  
  122.         DosSleep(5000);
  123.         t = (char *) malloc(100);
  124.         t[0] = 0;
  125.         WinPostMsg(myFrame,WM_USER,(MPARAM) t,0);
  126.     }
  127. }
  128.  
  129.  
  130. int main(int,char **)
  131. {
  132.     ULONG flCreate;
  133.  
  134.     myHab = WinInitialize(0);
  135.     myHmq = WinCreateMsgQueue(myHab,0);
  136.  
  137.     forkThread(listenToPort,(void *)0);
  138.     forkThread(clearDisplay,(void *)0);
  139.  
  140.     WinDlgBox(HWND_DESKTOP,HWND_DESKTOP,myPageWindowProc,0,1,0);
  141.  
  142.     WinDestroyMsgQueue(myHmq);
  143.     WinTerminate(myHab);
  144.  
  145.     return 0;
  146.  
  147. }
  148.  
  149.